#include "Adc.h"
#include<avr/io.h>
#include<avr/interrupt.h>
#include "../../../bit/bit.h"
#include "../../../counter/Counter.h"
#include "../../../flag/Flag.h"

using namespace Hardware::Avr;

Flag flag = Flag();
volatile unsigned long int value = 0;

int main()
{
	DDRA = 0xFF;
	PORTA = 0x00;
	DDRB = 0xFF;
	PORTB = 0xFF;
	AdcConfig config = AdcConfig();
	config.voltRef = Adc::AREF_Internal_Vref_Off;
	config.leftAdjust = 0;
	config.enable = 1;
	config.startConversion = 1;
	config.autoTrigger = 1;
	config.prescaler = Adc::Prescale2_1;
	config.triggerSource = Adc::FreeRunning;
	config.interrupt = 1;
	config.analogSelect = 0x1F; //ground select.

	//configure now
	Adc adc = Adc(config);
	adc.config();//configure the adc now.

	sei(); //enable interrupts
	while(1)
	{
		if(flag[0].getBit()==1)
		{
			flag[0].setBit(0);
			PORTA = (unsigned char) value;
		}
	}
	

}

ISR(ADC_vect)
{
	flag[0].setBit(1);
	value = ADCH;
	value = value << 8;
	value = value | ADCL;
}
